module.exports = (options, app) => {
  return async function (ctx, next) {
    const startTime = Date.now();
    ctx.set("X-Server-Time", startTime);
    await next();
    const consume = Date.now() - startTime;
    const { threshold = 0 } = options || {};
    if (consume > threshold) {
      // 如果耗时超过指定阈值就打印日志
      console.log(`${ctx.url}请求耗时${consume}毫秒`);
    }
  };
};
